#ifndef TEXTURE_MANAGER
#define TEXTURE_MANAGER

#include <d3d9.h>
#include <d3dx9.h>
#include <vector>
using std::vector;
#define ColorToKey(r,g,b) ( (0xFF<<24) | (r<<16) | (g<<8) | (b) )

class TextureManager
{
	typedef struct _TEXTURE
	{
		char				fileName[_MAX_PATH];
		int					refCount;
		LPDIRECT3DTEXTURE9	texture;
		int					width;
		int					height;

		_TEXTURE()
		{
			fileName[0] = 0;
			refCount = 0;
			texture = NULL;
			width = 0;
			height = 0;
		}
	} TEXTURE, *LPTEXTURE;

	vector<TEXTURE>			m_Textures;
	LPDIRECT3DDEVICE9		m_Device;
	LPD3DXSPRITE			m_Sprite;
	static TextureManager	m_Instance;

	TextureManager();
	TextureManager(TextureManager &instance);
	TextureManager &operator =(TextureManager &instance);
	~TextureManager();

public:

	static TextureManager* GetInstance();

	bool Initialize(LPDIRECT3DDEVICE9 device, LPD3DXSPRITE sprite);

	void Shutdown();

	int LoadTeture(const char* fileName, DWORD colorKey);

	bool UnloadTexture(int id);

	int GetTextureWidth(int id);

	int GetTextureHeight(int id);

	bool Draw(int id, int x, int y, float xScale = 1.0f, float yScale = 1.0f, RECT* pSection = NULL,
		float rotCenterX = 0.0f, float rotCenterY = 0.0f, float rotation = 0.0f, DWORD color = 0xFFFFFFFF);
};

#endif // TEXTURE_MANAGER